/******************************************************************
*** U.S. Enforcement Politics and Remittance Dynamics in Mexico ***
*** Modified 09/29/2023 										***
*******************************************************************/

/***** Preliminary steps. *****/
/* Establish initial conditions for Stata */
clear all
set more off, perm
version 16.0
/* Set the working directory */
global data "filepath"



/***** Compute descriptive statistics and generate maps. *****/
/* Import the data */
use "$data/prelim.dta", clear
/* Edit labels to enable indentation in LateX */
label var rem "\hspace{0.5cm} Remittances (USD mil.)"
label var dpt_tot_prop "\hspace{0.5cm} Deportations" 
label var sc_cons_raw "\hspace{0.5cm} Policy $\times$ Partisanship"
label var active_exp "\hspace{0.5cm} Policy"
label var cons_exp_raw "\hspace{0.5cm} Partisanship" 
label var pop "\hspace{0.5cm} Population (mil.)"
label var ann_pr_mx "\hspace{0.5cm} Precipitation (mm)"
label var avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)"
/*** Compute and translate descriptive statistics to LateX. In LateX, move code \bottomrule, \end{tabular}, and \end{table} to bottom of table. Next, establish 'article' as document class. After, install 'booktabs' and 'threeparttable' packages. Then add \begin{document} and \end{document} appropriately. Finally, set text in \scriptsize  ****/
/* Descriptive statistics for full time period */
estpost tabstat rem dpt_tot_prop sc_cons_raw active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx, c(stat) stat(n min p50 mean max sd)
esttab using "$data/desc.tex", replace refcat(rem "\emph{2003-2017}", nolabel) cells("count min(fmt(%12.3fc)) p50(fmt(%12.3fc)) mean(fmt(%12.3fc)) max(fmt(%12.3fc)) sd(fmt(%12.3fc))") nonumber nomtitle nonote noobs label booktabs collabels("N" "Minimum" "Median" "Mean" "Maximum" "Standard Deviation") title("Descriptive Statistics")
/* Descriptive statistics prior to Secure Communities in 2008 */
estpost tabstat rem dpt_tot_prop sc_cons_raw active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx if yr<2008, c(stat) stat(n min p50 mean max sd)
esttab using "$data/desc.tex", append refcat(rem "\emph{2003-2007}", nolabel) cells("count min(fmt(%12.3fc)) p50(fmt(%12.3fc)) mean(fmt(%12.3fc)) max(fmt(%12.3fc)) sd(fmt(%12.3fc))") nonumber nomtitle nonote noobs label booktabs collabels(none) fragment
/* Descriptive statistics for period of Secure Communities */
estpost tabstat rem dpt_tot_prop sc_cons_raw active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx if yr>=2008, c(stat) stat(n min p50 mean max sd)
esttab using "$data/desc.tex", append refcat(rem "\emph{2008-2017}", nolabel) cells("count min(fmt(%12.3fc)) p50(fmt(%12.3fc)) mean(fmt(%12.3fc)) max(fmt(%12.3fc)) sd(fmt(%12.3fc))") nonumber nomtitle nonote noobs label booktabs collabels(none) fragment
/* Twoway scatter plot of deportations on the instrument */
graph set window fontface "Times New Roman"
twoway (scatter dpt_tot_prop sc_cons_raw, mcolor(black) msymbol(Oh) xtitle("Policy × Partisanship", size(vlarge)) ytitle("Deportations", size(vlarge)) ylabel(, nogrid) graphregion(fcolor(white) lcolor(white) lwidth(vvvthick) ifcolor(white) ilcolor(white) ilwidth(vvvthick))) (lfit dpt_tot_prop sc_cons_raw, lcolor(black)), legend(off)
graph export "$data/tw_dpt_ins_con.png", replace
/* Twoway scatter plot of remittances on deportations */
twoway (scatter rem dpt_tot_prop, mcolor(black) msymbol(Oh) xtitle("Deportations", size(vlarge)) ytitle("Remittance inflows (USD mil.)", size(vlarge)) ylabel(, nogrid) graphregion(fcolor(white) lcolor(white) lwidth(vvvthick) ifcolor(white) ilcolor(white) ilwidth(vvvthick))) (lfit rem dpt_tot_prop, lcolor(black)), legend(off)
graph export "$data/tw_rem_dpt.png", replace
/* Check multicollinearity among the explanatory variables. Install package 'collin' from UCLA. */
	// search collin
collin sc_cons_raw active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx
pwcorr sc_cons_raw active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx



/***** Maps of Mexico. *****/
/*** Preliminary steps ***/
/* Put shapefile into workable form */
shp2dta using "$data/mexstates/mexstates.shp", database("$data/mxdata1A.dta") coordinates("$data/mxcoord1.dta") gencentroids(coord) genid(id) replace
/* Import workable shapefile */
use "$data/mxdata1A.dta", clear
/* Set states' names in lower case*/
replace ADMIN_NAME = lower(trim(ADMIN_NAME))
/* Add abbreviated names */
sort ADMIN_NAME
gen st_mx = ""
replace st_mx="AGS" if ADMIN_NAME=="aguascalientes"
replace st_mx="BCN" if ADMIN_NAME=="baja california"
replace st_mx="BCS" if ADMIN_NAME=="baja california sur"
replace st_mx="CAM" if ADMIN_NAME=="campeche"
replace st_mx="CHI" if ADMIN_NAME=="chihuahua"
replace st_mx="CHS" if ADMIN_NAME=="chiapas"
replace st_mx="COA" if ADMIN_NAME=="coahuila"
replace st_mx="COL" if ADMIN_NAME=="colima"
replace st_mx="DFE" if ADMIN_NAME=="distrito federal"
replace st_mx="DGO" if ADMIN_NAME=="durango"
replace st_mx="GRO" if ADMIN_NAME=="guerrero"
replace st_mx="GTO" if ADMIN_NAME=="guanajuato"
replace st_mx="HGO" if ADMIN_NAME=="hidalgo"
replace st_mx="JAL" if ADMIN_NAME=="jalisco"
replace st_mx="MEX" if ADMIN_NAME=="mexico"
replace st_mx="MIC" if ADMIN_NAME=="michoacan"
replace st_mx="MOR" if ADMIN_NAME=="morelos"
replace st_mx="NAY" if ADMIN_NAME=="nayarit"
replace st_mx="NLE" if ADMIN_NAME=="nuevo leon"
replace st_mx="OAX" if ADMIN_NAME=="oaxaca"
replace st_mx="PUE" if ADMIN_NAME=="puebla"
replace st_mx="QRO" if ADMIN_NAME=="queretaro"
replace st_mx="ROO" if ADMIN_NAME=="quintana roo"
replace st_mx="SIN" if ADMIN_NAME=="sinaloa"
replace st_mx="SLP" if ADMIN_NAME=="san luis potosi"
replace st_mx="SON" if ADMIN_NAME=="sonora"
replace st_mx="TAB" if ADMIN_NAME=="tabasco"
replace st_mx="TAM" if ADMIN_NAME=="tamaulipas"
replace st_mx="TLA" if ADMIN_NAME=="tlaxcala"
replace st_mx="VER" if ADMIN_NAME=="veracruz"
replace st_mx="YUC" if ADMIN_NAME=="yucatan"
replace st_mx="ZAC" if ADMIN_NAME=="zacatecas"
save "$data/mxdata1B.dta", replace

/*** Map of remittance inflows by Mexican state ***/
use "$data/prelim.dta", clear
/* Create quintiles manually */
merge m:1 st_mx using "$data/mxdata1B.dta"
drop _merge
centile rem, centile(20 40 60 80)
gen qrem_mx = .
replace qrem_mx = 1 if rem < 191.2681
replace qrem_mx = 2 if rem >= 191.2681 & rem < 374.327
replace qrem_mx = 3 if rem >= 374.327 & rem < 596.2227
replace qrem_mx = 4 if rem >= 596.2227 & rem < 1236.152
replace qrem_mx = 5 if rem >= 1236.152
/* Create quintiles automatically */
xtile qrem_xt=rem, n(5)
/* Compare manual and automatic quintiles */
pwcorr qrem_mx qrem_xt
groups qrem*
/* Create maps in 2004, 2008, and 2012 */
spmap qrem_mx using "$data/mxcoord1.dta" if yr==2004, id(id) clmethod(custom) clbreaks(0 1 2 3 4 5) legend(size(vlarge)) title("2004", size(huge)) legend(label(2 "[0, 191.2681)")) legend(label(3 "[191.2681–374.327)")) legend(label(4 "[374.327–596.2227)")) legend(label(5 "[596.2227–1236.152)")) legend(label(6 "[1236.152–)"))
graph export "$data/rem_04.png", replace
spmap qrem_mx using "$data/mxcoord1.dta" if yr==2008, id(id) clmethod(custom) clbreaks(0 1 2 3 4 5) legend(size(vlarge)) title("2008", size(huge)) legend(label(2 "[0, 191.2681)")) legend(label(3 "[191.2681–374.327)")) legend(label(4 "[374.327–596.2227)")) legend(label(5 "[596.2227–1236.152)")) legend(label(6 "[1236.152–)"))
graph export "$data/rem_08.png", replace
spmap qrem_mx using "$data/mxcoord1.dta" if yr==2012, id(id) clmethod(custom) clbreaks(0 1 2 3 4 5) legend(size(vlarge)) title("2012", size(huge)) legend(label(2 "[0, 191.2681)")) legend(label(3 "[191.2681–374.327)")) legend(label(4 "[374.327–596.2227)")) legend(label(5 "[596.2227–1236.152)")) legend(label(6 "[1236.152–)"))
graph export "$data/rem_12.png", replace

/*** Map of deportations by Mexican state ***/
/* Create quintiles manually */
centile dpt_tot_prop, centile(20 40 60 80)
gen qdpt_mx = .
replace qdpt_mx = 1 if dpt_tot_prop < 1971.209
replace qdpt_mx = 2 if dpt_tot_prop >= 1971.209 & dpt_tot_prop < 3662.373
replace qdpt_mx = 3 if dpt_tot_prop >= 3662.373 & dpt_tot_prop < 6545.293
replace qdpt_mx = 4 if dpt_tot_prop >= 6545.293 & dpt_tot_prop < 10265.03
replace qdpt_mx = 5 if dpt_tot_prop >= 10265.03
/* Create quintiles automatically */
xtile qdpt_xt=dpt_tot_prop, n(5)
/* Compare manual and automatic quintiles */
pwcorr qdpt_mx qdpt_xt
groups qdpt*
/* Map deportations in 2004, 2008, and 2012 */
spmap qdpt_mx using "$data/mxcoord1.dta" if yr==2004, id(id) clmethod(custom) clbreaks(0 1 2 3 4 5) legend(size(vlarge)) title("2004", size(huge)) legend(label(2 "[0, 1971.209)")) legend(label(3 "[1971.209–3662.373)")) legend(label(4 "[3662.373–6545.293)")) legend(label(5 "[6545.293–10265.03)")) legend(label(6 "[10265.03–)"))
graph export "$data/dpt_04.png", replace
spmap qdpt_mx using "$data/mxcoord1.dta" if yr==2008, id(id) clmethod(custom) clbreaks(0 1 2 3 4 5) legend(size(vlarge)) title("2008", size(huge)) legend(label(2 "[0, 1971.209)")) legend(label(3 "[1971.209–3662.373)")) legend(label(4 "[3662.373–6545.293)")) legend(label(5 "[6545.293–10265.03)")) legend(label(6 "[10265.03–)"))
graph export "$data/dpt_08.png", replace
spmap qdpt_mx using "$data/mxcoord1.dta" if yr==2012, id(id) clmethod(custom) clbreaks(0 1 2 3 4 5) legend(size(vlarge)) title("2012", size(huge)) legend(label(2 "[0, 1971.209)")) legend(label(3 "[1971.209–3662.373)")) legend(label(4 "[3662.373–6545.293)")) legend(label(5 "[6545.293–10265.03)")) legend(label(6 "[10265.03–)"))
graph export "$data/dpt_12.png", replace



/***** Maps of the U.S. *****/
/*** Preliminary steps ***/
/* Convert the American shapefile into a workable form */
shp2dta using "$data/tl_2019_us_state/tl_2019_us_state.shp", database($data/usdata.dta) coordinates($data/uscoord.dta) gencentroids(coord) genid(id) replace
/* Prepare the database file for merging */
use "$data/usdata.dta", clear
gen st_us=STUSPS
save "$data/usdata.dta", replace

/*** Maps of deportations by American state ***/
/* Import data */
use "$data/deport_us_4812.dta", clear
/* Merge with the geographical data. Drop states and territories outside the contiguous United States */
merge m:1 st_us using "$data/usdata.dta"
	// tab st_us if _merge==2
drop if _merge==2
drop _merge
/* Map deportations by quintile in 2004, 2008, and 2012 */
spmap qdpt_tot using "$data/uscoord.dta" if yr==2004, id(id) clmethod(custom) clbreaks(0 1 2 3 4 5) legend(size(large)) title("2004") legend(label(2 "[0, 3)")) legend(label(3 "[3–35)")) legend(label(4 "[35–207)")) legend(label(5 "[207–566)")) legend(label(6 "[566–)"))
graph export "$data/dpt_us_04.png", replace
spmap qdpt_tot using "$data/uscoord.dta" if yr==2008, id(id) clmethod(custom) clbreaks(0 1 2 3 4 5) legend(size(large)) title("2008") legend(label(2 "[0, 3)")) legend(label(3 "[3–35)")) legend(label(4 "[35–207)")) legend(label(5 "[207–566)")) legend(label(6 "[566–)"))
graph export "$data/dpt_us_08.png", replace
spmap qdpt_tot using "$data/uscoord.dta" if yr==2012, id(id) clmethod(custom) clbreaks(0 1 2 3 4 5) legend(size(large)) title("2012") legend(label(2 "[0, 3)")) legend(label(3 "[3–35)")) legend(label(4 "[35–207)")) legend(label(5 "[207–566)")) legend(label(6 "[566–)"))
graph export "$data/dpt_us_12.png", replace

/*** Maps of Secure Communities ***/
/* Import data then merge with geographical data. Drop states and territories outside the contiguous United States */
use "$data/active_map", clear
sort us_id yr
merge m:1 st_us using "$data/usdata.dta"
	// tab st_us if _merge==2
drop if _merge==2
drop _merge
/* Map the cumulative proportion of states' activated counties in 2008, 2012, and 2014 */
spmap active_prop using "$data/uscoord.dta" if yr==2008, id(id) clmethod(custom) clbreaks(0 0.2 0.4 0.6 0.8 1) legend(size(large)) title("2008") legend(label(2 "0 - 20%")) legend(label(3 "21 - 40%")) legend(label(4 "41 - 60%")) legend(label(5 "61 - 80%")) legend(label(6 "81 - 100%"))
graph export "$data/act_us_08.png", replace
spmap active_prop using "$data/uscoord.dta" if yr==2010, id(id) clmethod(custom) clbreaks(0 0.2 0.4 0.6 0.8 1) legend(size(large)) title("2010") legend(label(2 "0 - 20%")) legend(label(3 "21 - 40%")) legend(label(4 "41 - 60%")) legend(label(5 "61 - 80%")) legend(label(6 "81 - 100%"))
graph export "$data/act_us_10.png", replace
spmap active_prop using "$data/uscoord.dta" if yr==2012, id(id) clmethod(custom) clbreaks(0 0.2 0.4 0.6 0.8 1) legend(size(large)) title("2012") legend(label(2 "0 - 20%")) legend(label(3 "21 - 40%")) legend(label(4 "41 - 60%")) legend(label(5 "61 - 80%")) legend(label(6 "81 - 100%"))
graph export "$data/act_us_12.png", replace


/*** Maps of exposure to Republican voters ***/
/* Import data on presidantial vote shares */
use "$data/elec_us.dta", clear
/* Drop states and territories outside the contiguous United States */
drop if us_id==1 | us_id==12 | us_id==13 | us_id==53 | us_id==54 | us_id==55
/* Merge with geographical data */
merge m:1 st_us using "$data/usdata.dta"
/* Drop states and territories outside the contiguous United States */
	// tab st_us if _merge==2
drop if _merge==2
drop _merge
/* Map presidential vote shares in 2004, 2008, and 2012 */
spmap rep_raw using "$data/uscoord.dta" if yr==2004, id(id) clmethod(custom) clbreaks(0 0.2 0.4 0.6 0.8 1) legend(size(large)) title("2004") legend(label(2 "0 - 20%")) legend(label(3 "21 - 40%")) legend(label(4 "41 - 60%")) legend(label(5 "61 - 80%")) legend(label(6 "81 - 100%"))
graph export "$data/vote_us_04.png", replace
spmap rep_raw using "$data/uscoord.dta" if yr==2008, id(id) clmethod(custom) clbreaks(0 0.2 0.4 0.6 0.8 1) legend(size(large)) title("2008") legend(label(2 "0 - 20%")) legend(label(3 "21 - 40%")) legend(label(4 "41 - 60%")) legend(label(5 "61 - 80%")) legend(label(6 "81 - 100%"))
graph export "$data/vote_us_08.png", replace
spmap rep_raw using "$data/uscoord.dta" if yr==2012, id(id) clmethod(custom) clbreaks(0 0.2 0.4 0.6 0.8 1) legend(size(large)) title("2012") legend(label(2 "0 - 20%")) legend(label(3 "21 - 40%")) legend(label(4 "41 - 60%")) legend(label(5 "61 - 80%")) legend(label(6 "81 - 100%"))
graph export "$data/vote_us_12.png", replace



/***** Conduct regression analysis *****/
/*** Ordinary least squares regression with robust standard errors as well as state and year fixed effects. Use the first state and year as the reference category ***/
/* Import the data */
use "$data/prelim.dta", clear
/* Raw data */
// Clear storage
eststo clear
// Without control variables
eststo: xi: reg rem dpt_tot_prop ib(first).yr ib(first).mx_id, robust
// With control variables
eststo: xi: reg rem dpt_tot_prop pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust
/* Winsorized data (0.5, 99.5) */
winsor2 rem dpt_tot_prop, cuts(0.5 99.5) suffix(_w1)
// Without control variables
eststo: xi: reg rem_w1 dpt_tot_prop_w1 ib(first).yr ib(first).mx_id, robust
// With control variables
eststo: xi: reg rem_w1 dpt_tot_prop_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately. Add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. Finally, moves notes from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Set notes in \footnotesize */
esttab est1 est2 est3 est4 using "$data/ols.tex", replace b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) label nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_tot_prop_w1 dpt_tot_prop) stats(N F p r2, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F \(R\)$^{2}$ )) nonote addnote("OLS regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs

/*** Instrumental variable regression with robust standard errors as well as state and year fixed effects. Use the first state and year as the reference category ***/
/* Raw data */
// Clear storage 
eststo clear
// Without control variables
tsset mx_id yr
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est1_)
// With control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est2_)
/* Winsorized data (0.5, 99.5) */
winsor2 active_exp cons_exp_raw, cuts(0.5 99.5) suffix(_w1)
gen sc_cons_raw_w1 = active_exp_w1*cons_exp_raw_w1
// Without control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est3_)
// With control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est4_)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately, then add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. After, set table font size to \footnotesize. Next, move final eight lines of first table to end of second table. Delete \midrule between the the tables. Penultimately, consolidate notes by moving all of them from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Set notes in \scriptsize. Last, put separate terms in Kleibergen-Paap F statistic.  */
esttab est1 est2 est3 est4 using "$data/iv.tex", replace refcat(dpt_tot_prop "\emph{Second Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) varlabels(dpt_tot_prop "\hspace{0.5cm} Deportations" active_exp "\hspace{0.5cm} Policy" cons_exp_raw "\hspace{0.5cm} Partisanship" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_tot_prop_w1 dpt_tot_prop active_exp_w1 active_exp cons_exp_raw_w1 cons_exp_raw) stats(N F Fp widstat, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F Kleibergen-Paap\(F\)statistic)) addnote("IV regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs
/* Append first stage results */ 
esttab est1_dpt_tot_prop est2_dpt_tot_prop est3_dpt_tot_prop_w1 est4_dpt_tot_prop_w1 using "$data/iv.tex", append refcat(sc_cons_raw "\emph{First Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) nomtitle varlabels(sc_cons_raw "\hspace{0.5cm} Policy $\times$ Partisanship" active_exp "\hspace{0.5cm} Policy" cons_exp_raw "\hspace{0.5cm} Partisanship" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber rename(sc_cons_raw_w1 sc_cons_raw active_exp_w1 active_exp cons_exp_raw_w1 cons_exp_raw) collabels(none) noobs booktabs fragment


/*** Identify  largest annual changes in deportations ***/
sort mx_id yr
by mx_id: gen dpt_ch = dpt_tot_prop - dpt_tot_prop[_n-1]
sort dpt_ch

/*** Anderson-Rubin confidence intervals. Create table manually in LATEX. ***/
/* Original data */
// Without control variables
sort mx_id yr
xi: ivreg2 rem (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw ib(first).yr ib(first).mx_id, robust first
weakiv
// With control variables
xi: ivreg2 rem (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first
weakiv
/* Winsorized data (0.5, 99.5) */
// Without control variables
xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 ib(first).yr ib(first).mx_id, robust first
weakiv
// With control variables
xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first
weakiv



/***** Tests of the exclusion restriction *****/
/*** Conduct regression analysis ***/
/** Exposure to unemployment in U.S. as instrumented variable **/
// Clear storage
eststo clear
// Original data 
eststo: xi: reg unemp_exp_wt sc_cons_raw active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust
// Winsorized data (0.5, 99.5)
winsor2 unemp_exp_wt, cuts(0.5 99.5) suffix(_w1)
eststo: xi: reg unemp_exp_wt_w1 sc_cons_raw_w1 active_exp_w1 cons_exp_raw_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust

/** Exposure to American wages as instrumented variable **/
/*  Data from COSP */
// Original data
eststo: xi: reg wage_csp_wt sc_cons_raw active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust
// Winsorized data (0.5, 99.5)
winsor2 wage_csp_wt, cuts(0.5 99.5) suffix(_w1)
eststo: xi: reg wage_csp_wt_w1 sc_cons_raw_w1 active_exp_w1 cons_exp_raw_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust

/* Data from MMP */
// Original data
eststo: xi: reg w_mmp_wt sc_cons_raw active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust
// Winsorized data (0.5, 99.5)
winsor2 w_mmp_wt, cuts(0.5 99.5) suffix(_w1)
eststo: xi: reg w_mmp_wt_w1 sc_cons_raw_w1 active_exp_w1 cons_exp_raw_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust
// Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs', 'threeparttable', and 'pdflscape' packages. Next, add \begin{document} and \end{document} appropriately. After, add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. Move notes from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Set table in \footnotesize and notes in \scriptsize. Finally, add headers to denote models in which wages and unemployment serve as dependent variable
esttab est1 est2 est3 est4 est5 est6 using "$data/exc.tex", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) drop(*yr *mx_id) label nonumber mtitle("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}" "\textit{Original}" "\textit{Winsorized (0.5, 99.5)}" "\textit{Original}" "\textit{Winsorized (0.5, 99.5)}") mgroups("" "Correlates of State Policy" "Mexican Migration Project", pattern(1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Policy and Partisanship on Exposure to Wages and Unemployment in the U.S.) rename(unemp_exp_wt_w1 unemp_exp_wt wage_csp_wt wage_csp_wt_w1 w_mmp_wt w_mmp_wt_w1 sc_cons_raw_w1 sc_cons_raw active_exp_w1 active_exp cons_exp_raw_w1 cons_exp_raw) stats(N F p r2, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F \(R\)$^{2}$ )) addnote("OLS regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") booktabs



/***** Conduct regression with standardized coefficients *****/
/*** Instrumental variable regression with standardized explanatory variables, robust standard errors as well as state and year fixed effects. Use the first state and year as the reference category. ***/
/* Raw data */
// Clear storage
eststo clear
// Without control variables
tsset mx_id yr
eststo: xi: ivreg2 rem (dpt_st=ins_st) active_st cons_st ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est1_)
// With control variables
eststo: xi: ivreg2 rem (dpt_st=ins_st) active_st cons_st pop_st pr_st tmp_st ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est2_)
/* Winsorized data (0.5, 99.5) */
	// sum dpt_tot_prop_w1
gen dpt_st_win = (dpt_tot_prop_w1 - 6680.299)/5753.619
	// sum active_exp_w1 cons_exp_raw_w1
gen act_st_win = (active_exp_w1-2.188262)/2.279328 
gen cons_st_win = (cons_exp_raw_w1-1.977921)/0.6595049
gen ins_st_win = act_st_win*cons_st_win
// Without control variables
eststo: xi: ivreg2 rem_w1 (dpt_st_win=ins_st_win) act_st_win cons_st_win ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est3_)
// With control variables
eststo: xi: ivreg2 rem_w1 (dpt_st_win=ins_st_win) act_st_win cons_st_win pop_st pr_st tmp_st ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est4_)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately, then add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. After, set table font size to \footnotesize and notes font size to \scriptsize. Next, move final eight lines of first table to end of second table. Delete \midrule between the tables. Penultimately, consolidate notes by moving all of them from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Last, separate the terms in Kleibergen-Paap F statistic.  */
esttab est1 est2 est3 est4 using "$data/iv_st.tex", replace refcat(dpt_st "\emph{Second Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) varlabels(dpt_st "\hspace{0.5cm} Deportations" active_st "\hspace{0.5cm} Policy" cons_st "\hspace{0.5cm} Partisanship" pop_st "\hspace{0.5cm} Population (mil.)" pr_st "\hspace{0.5cm} Precipitation (mm)" tmp_st "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_st_win dpt_st ins_st_win ins_st act_st_win active_st cons_st_win cons_st) stats(N F Fp widstat, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F Kleibergen-Paap\(F\)statistic)) addnote("IV regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs
/* Append first stage results */ 
esttab est1_dpt_st est2_dpt_st est3_dpt_st_win est4_dpt_st_win using "$data/iv_st.tex", append refcat(ins_st "\emph{First Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) nomtitle varlabels(ins_st "\hspace{0.5cm} Policy $\times$ Partisanship" active_st "\hspace{0.5cm} Policy" cons_st "\hspace{0.5cm} Partisanship" pop_st "\hspace{0.5cm} Population (mil.)" pr_st "\hspace{0.5cm} Precipitation (mm)" tmp_st "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber rename(dpt_st_win dpt_st ins_st_win ins_st act_st_win active_st cons_st_win cons_st) collabels(none) noobs booktabs fragment



/***** Regression analysis with clustered standard errors *****/
/* Raw data */
// Clear storage
eststo clear
// Without control variables
eststo: xi: reg rem dpt_tot_prop ib(first).yr ib(first).mx_id, cluster(mx_id)
// With control variables
eststo: xi: reg rem dpt_tot_prop pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, cluster(mx_id)
/* Winsorized data (0.5, 99.5) */
// Without control variables
eststo: xi: reg rem_w1 dpt_tot_prop_w1 ib(first).yr ib(first).mx_id, cluster(mx_id)
// With control variables
eststo: xi: reg rem_w1 dpt_tot_prop_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, cluster(mx_id)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately. After, add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. Finally, moves notes from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Set notes in \footnotesize */
esttab est1 est2 est3 est4 using "$data/ols_clst.tex", replace b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) label nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_tot_prop_w1 dpt_tot_prop) stats(N F p r2, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F \(R\)$^{2}$ )) addnote("OLS regression. Clustered standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs

/*** Instrumental variable regression with clustered standard errors as well as state and year fixed effects. Cluster by state. Use the first state and year as the reference category. ***/
/* Raw data */
// Clear storage
eststo clear
// Without control variables
tsset mx_id yr
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw ib(first).yr ib(first).mx_id, cluster(mx_id) first savefirst savefprefix(est1_)
// With control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, cluster(mx_id) first savefirst savefprefix(est2_)
/* Winsorized data (0.5, 99.5) */
// Without control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 ib(first).yr ib(first).mx_id, cluster(mx_id) first savefirst savefprefix(est3_)
// With control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, cluster(mx_id) first savefirst savefprefix(est4_)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately, then add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. After, set table font size to \footnotesize. Set notes in \scriptsize. Next, move final eight lines of first table to end of second table. Delete \midrule between the the tables. Penultimately, consolidate notes by moving all of them from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Last, separate the terms in Kleibergen-Paap F statistic.  */
esttab est1 est2 est3 est4 using "$data/iv_clst.tex", replace refcat(dpt_tot_prop "\emph{Second Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) varlabels(dpt_tot_prop "\hspace{0.5cm} Deportations" active_exp "\hspace{0.5cm} Policy" cons_exp_raw "\hspace{0.5cm} Partisanship" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_tot_prop_w1 dpt_tot_prop active_exp_w1 active_exp cons_exp_raw_w1 cons_exp_raw) stats(N F Fp widstat, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F Kleibergen-Paap\(F\)statistic)) addnote("IV regression. Clustered standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs
/* Append first stage results */ 
esttab est1_dpt_tot_prop est2_dpt_tot_prop est3_dpt_tot_prop_w1 est4_dpt_tot_prop_w1 using "$data/iv_clst.tex", append refcat(sc_cons_raw "\emph{First Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) nomtitle varlabels(sc_cons_raw "\hspace{0.5cm} Policy $\times$ Partisanship" active_exp "\hspace{0.5cm} Policy" cons_exp_raw "\hspace{0.5cm} Partisanship" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber rename(sc_cons_raw_w1 sc_cons_raw active_exp_w1 active_exp cons_exp_raw_w1 cons_exp_raw) collabels(none) noobs booktabs fragment



/***** Conduct regression with emigrant outflows as a control variable *****/
/*** Conduct regression analysis with emigrant outflows as a control variable ***/
/** Instrumental variable regression with robust standard errors as well as state and year fixed effects. Use the first state and year as the reference category. **/
/* Original data */
// Clear storage
eststo clear
// Without control variables
tsset mx_id yr
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est1_)
// With control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw emig ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est2_)
/* Winsorized data (0.5, 99.5) */
// Without control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est3_)
// With control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 emig ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est4_)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately, then add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. After, set table font size to \footnotesize. Set notes in \scriptsize. Next, move final eight lines of first table to end of second table. Delete \midrule between the the tables. Penultimately, consolidate notes by moving all of them from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Last, separate the terms in Kleibergen-Paap F statistic.  */
esttab est1 est2 est3 est4 using "$data/iv_emig.tex", replace refcat(dpt_tot_prop "\emph{Second Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) varlabels(dpt_tot_prop "\hspace{0.5cm} Deportations" active_exp "\hspace{0.5cm} Policy" cons_exp_raw "\hspace{0.5cm} Partisanship" emig "\hspace{0.5cm} Emigration" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_tot_prop_w1 dpt_tot_prop active_exp_w1 active_exp cons_exp_raw_w1 cons_exp_raw) stats(N F Fp widstat, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F Kleibergen-Paap\(F\)statistic)) addnote("IV regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs
/* Append first stage results */ 
esttab est1_dpt_tot_prop est2_dpt_tot_prop est3_dpt_tot_prop_w1 est4_dpt_tot_prop_w1 using "$data/iv_emig.tex", append refcat(sc_cons_raw "\emph{First Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) nomtitle varlabels(sc_cons_raw "\hspace{0.5cm} Policy $\times$ Partisanship" active_exp "\hspace{0.5cm} Policy" cons_exp_raw "\hspace{0.5cm} Partisanship" emig "\hspace{0.5cm} Emigration" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber rename(sc_cons_raw_w1 sc_cons_raw active_exp_w1 active_exp cons_exp_raw_w1 cons_exp_raw) collabels(none) noobs booktabs fragment



/***** Repeat instrumental variable analysis with pre-treatment and lagged vote shares *****/
/** Vote shares from 2000 **/
/* Raw data */
// Clear storage 
eststo clear
// Without control variables
tsset mx_id yr
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_2000) active_exp cons_exp_2000 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est1_)
// With control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_2000) active_exp cons_exp_2000 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est2_)
/* Winsorized data (0.5, 99.5) */
winsor2 cons_exp_2000, cuts(0.5 99.5) suffix(_w1)
gen sc_cons_2000_w1 = active_exp_w1*cons_exp_2000_w1
// Without control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_2000_w1) active_exp_w1 cons_exp_2000_w1 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est3_)
// With control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_2000_w1) active_exp_w1 cons_exp_2000_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est4_)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately, then add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. After, set table font size to \footnotesize. Set notes in \scriptsize. Next, move final eight lines of first table to end of second table. Delete \midrule between the tables. Penultimately, consolidate notes by moving all of them from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Last, separate the terms in Kleibergen-Paap F statistic.  */
esttab est1 est2 est3 est4 using "$data/iv_2000.tex", replace refcat(dpt_tot_prop "\emph{Second Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) varlabels(dpt_tot_prop "\hspace{0.5cm} Deportations" active_exp "\hspace{0.5cm} Policy" cons_exp_2000 "\hspace{0.5cm} Partisanship (2000)" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_tot_prop_w1 dpt_tot_prop active_exp_w1 active_exp cons_exp_2000_w1 cons_exp_2000) stats(N F Fp widstat, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F Kleibergen-Paap\(F\)statistic)) addnote("IV regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs
/* Append first stage results */ 
esttab est1_dpt_tot_prop est2_dpt_tot_prop est3_dpt_tot_prop_w1 est4_dpt_tot_prop_w1 using "$data/iv_2000.tex", append refcat(sc_cons_2000 "\emph{First Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) nomtitle varlabels(sc_cons_2000 "\hspace{0.5cm} Policy $\times$ Partisanship (2000)" active_exp "\hspace{0.5cm} Policy" cons_exp_2000 "\hspace{0.5cm} Partisanship (2000)" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber rename(sc_cons_2000_w1 sc_cons_2000 active_exp_w1 active_exp cons_exp_2000_w1 cons_exp_2000) collabels(none) noobs booktabs fragment

/** Vote shares from 2004 **/
/* Raw data */
// Clear storage 
eststo clear
// Without control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_2004) active_exp cons_exp_2004 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est1_)
// With control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_2004) active_exp cons_exp_2004 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est2_)
/* Winsorized data (0.5, 99.5) */
winsor2 cons_exp_2004, cuts(0.5 99.5) suffix(_w1)
gen sc_cons_2004_w1 = active_exp_w1*cons_exp_2004_w1
// Without control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_2004_w1) active_exp_w1 cons_exp_2004_w1 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est3_)
// With control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_2004_w1) active_exp_w1 cons_exp_2004_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est4_)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately, then add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. After, set table font size to \footnotesize. Set notes in \scriptsize. Next, move final eight lines of first table to end of second table. Delete \midrule between the tables. Penultimately, consolidate notes by moving all of them from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Last, separate the terms in Kleibergen-Paap F statistic.  */
esttab est1 est2 est3 est4 using "$data/iv_2004.tex", replace refcat(dpt_tot_prop "\emph{Second Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) varlabels(dpt_tot_prop "\hspace{0.5cm} Deportations" active_exp "\hspace{0.5cm} Policy" cons_exp_2004 "\hspace{0.5cm} Partisanship (2004)" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_tot_prop_w1 dpt_tot_prop active_exp_w1 active_exp cons_exp_2004_w1 cons_exp_2004) stats(N F Fp widstat, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F Kleibergen-Paap\(F\)statistic)) addnote("IV regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs
/* Append first stage results */ 
esttab est1_dpt_tot_prop est2_dpt_tot_prop est3_dpt_tot_prop_w1 est4_dpt_tot_prop_w1 using "$data/iv_2004.tex", append refcat(sc_cons_2004 "\emph{First Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) nomtitle varlabels(sc_cons_2004 "\hspace{0.5cm} Policy $\times$ Partisanship (2004)" active_exp "\hspace{0.5cm} Policy" cons_exp_2004 "\hspace{0.5cm} Partisanship (2004)" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber rename(sc_cons_2004_w1 sc_cons_2004 active_exp_w1 active_exp cons_exp_2004_w1 cons_exp_2004) collabels(none) noobs booktabs fragment

/** Mean vote share from 2000 to 2004 **/
/* Raw data */
// Clear storage 
eststo clear
// Without control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_0004) active_exp cons_exp_0004 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est1_)
// With control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_0004) active_exp cons_exp_0004 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est2_)
/* Winsorized data (0.5, 99.5) */
winsor2 cons_exp_0004, cuts(0.5 99.5) suffix(_w1)
gen sc_cons_0004_w1 = active_exp_w1*cons_exp_0004_w1
// Without control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_0004_w1) active_exp_w1 cons_exp_0004_w1 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est3_)
// With control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_0004_w1) active_exp_w1 cons_exp_0004_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est4_)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately, then add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. After, set table font size to \footnotesize. Set notes in \scriptsize. Next, move final eight lines of first table to end of second table. Delete \midrule between the tables. Penultimately, consolidate notes by moving all of them from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Last, separate the terms in Kleibergen-Paap F statistic.  */
esttab est1 est2 est3 est4 using "$data/iv_0004.tex", replace refcat(dpt_tot_prop "\emph{Second Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) varlabels(dpt_tot_prop "\hspace{0.5cm} Deportations" active_exp "\hspace{0.5cm} Policy" cons_exp_0004 "\hspace{0.5cm} Partisanship (2000--2004)" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_tot_prop_w1 dpt_tot_prop active_exp_w1 active_exp cons_exp_0004_w1 cons_exp_0004) stats(N F Fp widstat, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F Kleibergen-Paap\(F\)statistic)) addnote("IV regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs
/* Append first stage results */ 
esttab est1_dpt_tot_prop est2_dpt_tot_prop est3_dpt_tot_prop_w1 est4_dpt_tot_prop_w1 using "$data/iv_0004.tex", append refcat(sc_cons_0004 "\emph{First Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) nomtitle varlabels(sc_cons_0004 "\hspace{0.5cm} Policy $\times$ Partisanship (2000--2004)" active_exp "\hspace{0.5cm} Policy" cons_exp_0004 "\hspace{0.5cm} Partisanship (2000--2004)" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber rename(sc_cons_0004_w1 sc_cons_0004 active_exp_w1 active_exp cons_exp_0004_w1 cons_exp_0004) collabels(none) noobs booktabs fragment

/** Mean vote share from 2000 to 2008 **/
/* Raw data */
// Clear storage 
eststo clear
// Without control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_0008) active_exp cons_exp_0008 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est1_)
// With control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_0008) active_exp cons_exp_0008 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est2_)
/* Winsorized data (0.5, 99.5) */
winsor2 cons_exp_0008, cuts(0.5 99.5) suffix(_w1)
gen sc_cons_0008_w1 = active_exp_w1*cons_exp_0008_w1
// Without control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_0008_w1) active_exp_w1 cons_exp_0008_w1 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est3_)
// With control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_0008_w1) active_exp_w1 cons_exp_0008_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est4_)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately, then add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. After, set table font size to \footnotesize. Set notes in \scriptsize. Next, move final eight lines of first table to end of second table. Delete \midrule between the tables. Penultimately, consolidate notes by moving all of them from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Last, separate the terms in Kleibergen-Paap F statistic.  */
esttab est1 est2 est3 est4 using "$data/iv_0008.tex", replace refcat(dpt_tot_prop "\emph{Second Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) varlabels(dpt_tot_prop "\hspace{0.5cm} Deportations" active_exp "\hspace{0.5cm} Policy" cons_exp_0008 "\hspace{0.5cm} Partisanship (2000--2008)" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_tot_prop_w1 dpt_tot_prop active_exp_w1 active_exp cons_exp_0008_w1 cons_exp_0008) stats(N F Fp widstat, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F Kleibergen-Paap\(F\)statistic)) addnote("IV regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs
/* Append first stage results */ 
esttab est1_dpt_tot_prop est2_dpt_tot_prop est3_dpt_tot_prop_w1 est4_dpt_tot_prop_w1 using "$data/iv_0008.tex", append refcat(sc_cons_0008 "\emph{First Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) nomtitle varlabels(sc_cons_0008 "\hspace{0.5cm} Policy $\times$ Partisanship (2000--2008)" active_exp "\hspace{0.5cm} Policy" cons_exp_0008 "\hspace{0.5cm} Partisanship (2000--2008)" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber rename(sc_cons_0008_w1 sc_cons_0008 active_exp_w1 active_exp cons_exp_0008_w1 cons_exp_0008) collabels(none) noobs booktabs fragment

/** Single-lag vote share **/
/* Raw data */
// Clear storage 
eststo clear
// Without control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_l1) active_exp cons_exp_l1 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est1_)
// With control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_l1) active_exp cons_exp_l1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est2_)
/* Winsorized data (0.5, 99.5) */
winsor2 cons_exp_l1, cuts(0.5 99.5) suffix(_w1)
gen sc_cons_l1_w1 = active_exp_w1*cons_exp_l1_w1
// Without control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_l1_w1) active_exp_w1 cons_exp_l1_w1 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est3_)
// With control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_l1_w1) active_exp_w1 cons_exp_l1_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est4_)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately, then add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. After, set table font size to \footnotesize. Set notes in \scriptsize. Next, move final eight lines of first table to end of second table. Delete \midrule between the tables. Penultimately, consolidate notes by moving all of them from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Last, separate the terms in Kleibergen-Paap F statistic.  */
esttab est1 est2 est3 est4 using "$data/iv_l1.tex", replace refcat(dpt_tot_prop "\emph{Second Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) varlabels(dpt_tot_prop "\hspace{0.5cm} Deportations" active_exp "\hspace{0.5cm} Policy" cons_exp_l1 "\hspace{0.5cm} Partisanship (lagged)" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_tot_prop_w1 dpt_tot_prop active_exp_w1 active_exp cons_exp_l1_w1 cons_exp_l1) stats(N F Fp widstat, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F Kleibergen-Paap\(F\)statistic)) addnote("IV regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs
/* Append first stage results */ 
esttab est1_dpt_tot_prop est2_dpt_tot_prop est3_dpt_tot_prop_w1 est4_dpt_tot_prop_w1 using "$data/iv_l1.tex", append refcat(sc_cons_l1 "\emph{First Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) nomtitle varlabels(sc_cons_l1 "\hspace{0.5cm} Policy $\times$ Partisanship (lagged)" active_exp "\hspace{0.5cm} Policy" cons_exp_l1 "\hspace{0.5cm} Partisanship (lagged)" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber rename(sc_cons_l1_w1 sc_cons_l1 active_exp_w1 active_exp cons_exp_l1_w1 cons_exp_l1) collabels(none) noobs booktabs fragment



/***** Z scores of remittance flows *****/
/** Instrumental variable regression with annual Z scores **/
/* Raw data */
// Clear storage 
eststo clear
// Without control variables
eststo: xi: ivreg2 ann_z (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est1_)
// With control variables
eststo: xi: ivreg2 ann_z (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est2_)
/* Winsorized data (0.5, 99.5) */
winsor2 ann_z, cuts(0.5 99.5) suffix(_w1)
// Without control variables
eststo: xi: ivreg2 ann_z_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est3_)
// With control variables
eststo: xi: ivreg2 ann_z_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est4_)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately, then add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. After, set table font size to \footnotesize. Next, move final eight lines of first table to end of second table. Delete \midrule between the the tables. Penultimately, consolidate notes by moving all of them from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Set notes in \scriptsize. Last, put separate terms in Kleibergen-Paap F statistic.  */
esttab est1 est2 est3 est4 using "$data/iv_ann_z.tex", replace refcat(dpt_tot_prop "\emph{Second Stage}", nolabel) b(5) se(5) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) varlabels(dpt_tot_prop "\hspace{0.5cm} Deportations" active_exp "\hspace{0.5cm} Policy" cons_exp_raw "\hspace{0.5cm} Partisanship" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' \newline Annual \textit{Z} Score) rename(dpt_tot_prop_w1 dpt_tot_prop active_exp_w1 active_exp cons_exp_raw_w1 cons_exp_raw) stats(N F Fp widstat, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F Kleibergen-Paap\(F\)statistic)) addnote("IV regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs
/* Append first stage results */ 
esttab est1_dpt_tot_prop est2_dpt_tot_prop est3_dpt_tot_prop_w1 est4_dpt_tot_prop_w1 using "$data/iv_ann_z.tex", append refcat(sc_cons_raw "\emph{First Stage}", nolabel) b(5) se(5) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) nomtitle varlabels(sc_cons_raw "\hspace{0.5cm} Policy $\times$ Partisanship" active_exp "\hspace{0.5cm} Policy" cons_exp_raw "\hspace{0.5cm} Partisanship" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber rename(sc_cons_raw_w1 sc_cons_raw active_exp_w1 active_exp cons_exp_raw_w1 cons_exp_raw) collabels(none) noobs booktabs fragment



/***** Test for documentation of remitters by analyzing the similarity of destination choice among Mexican states' documented and undocumented migrants *****/
/*** Instrumental variable regression for sample of Mexican states with more dissimilar enclave locations ***/
/* Raw data */
// Clear storage 
eststo clear
// Without control variables
tsset mx_id yr
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw ib(first).yr ib(first).mx_id if qdest==1, robust first savefirst savefprefix(est1_)
// With control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id if qdest==1, robust first savefirst savefprefix(est2_)
/* Winsorized data (0.5, 99.5) */
// Without control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 ib(first).yr ib(first).mx_id if qdest==1, robust first savefirst savefprefix(est3_)
// With control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id if qdest==1, robust first savefirst savefprefix(est4_)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately, then add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. After, set table font size to \footnotesize. Next, move final eight lines of first table to end of second table. Delete \midrule between the the tables. Penultimately, consolidate notes by moving all of them from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Set notes in \scriptsize. Last, put separate terms in Kleibergen-Paap F statistic.  */
esttab est1 est2 est3 est4 using "$data/iv_ft1.tex", replace refcat(dpt_tot_prop "\emph{Second Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) varlabels(dpt_tot_prop "\hspace{0.5cm} Deportations" active_exp "\hspace{0.5cm} Policy" cons_exp_raw "\hspace{0.5cm} Partisanship" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_tot_prop_w1 dpt_tot_prop active_exp_w1 active_exp cons_exp_raw_w1 cons_exp_raw) stats(N F Fp widstat, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F Kleibergen-Paap\(F\)statistic)) addnote("IV regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs
/* Append first stage results */ 
esttab est1_dpt_tot_prop est2_dpt_tot_prop est3_dpt_tot_prop_w1 est4_dpt_tot_prop_w1 using "$data/iv_ft1.tex", append refcat(sc_cons_raw "\emph{First Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) nomtitle varlabels(sc_cons_raw "\hspace{0.5cm} Policy $\times$ Partisanship" active_exp "\hspace{0.5cm} Policy" cons_exp_raw "\hspace{0.5cm} Partisanship" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber rename(sc_cons_raw_w1 sc_cons_raw active_exp_w1 active_exp cons_exp_raw_w1 cons_exp_raw) collabels(none) noobs booktabs fragment

/*** Instrumental variable regression for sample of Mexican states with highly similar enclave locations ***/
/* Raw data */
// Clear storage 
eststo clear
// Without control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw ib(first).yr ib(first).mx_id if qdest==2, robust first savefirst savefprefix(est1_)
// With control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_cons_raw) active_exp cons_exp_raw pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id if qdest==2, robust first savefirst savefprefix(est2_)
/* Winsorized data (0.5, 99.5) */
// Without control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 ib(first).yr ib(first).mx_id if qdest==2, robust first savefirst savefprefix(est3_)
// With control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_cons_raw_w1) active_exp_w1 cons_exp_raw_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id if qdest==2, robust first savefirst savefprefix(est4_)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately, then add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. After, set table font size to \footnotesize. Next, move final eight lines of first table to end of second table. Delete \midrule between the the tables. Penultimately, consolidate notes by moving all of them from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Set notes in \scriptsize. Last, put separate terms in Kleibergen-Paap F statistic.  */
esttab est1 est2 est3 est4 using "$data/iv_ft2.tex", replace refcat(dpt_tot_prop "\emph{Second Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) varlabels(dpt_tot_prop "\hspace{0.5cm} Deportations" active_exp "\hspace{0.5cm} Policy" cons_exp_raw "\hspace{0.5cm} Partisanship" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_tot_prop_w1 dpt_tot_prop active_exp_w1 active_exp cons_exp_raw_w1 cons_exp_raw) stats(N F Fp widstat, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F Kleibergen-Paap\(F\)statistic)) addnote("IV regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs
/* Append first stage results */ 
esttab est1_dpt_tot_prop est2_dpt_tot_prop est3_dpt_tot_prop_w1 est4_dpt_tot_prop_w1 using "$data/iv_ft2.tex", append refcat(sc_cons_raw "\emph{First Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) nomtitle varlabels(sc_cons_raw "\hspace{0.5cm} Policy $\times$ Partisanship" active_exp "\hspace{0.5cm} Policy" cons_exp_raw "\hspace{0.5cm} Partisanship" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber rename(sc_cons_raw_w1 sc_cons_raw active_exp_w1 active_exp cons_exp_raw_w1 cons_exp_raw) collabels(none) noobs booktabs fragment



/***** Main analyses with anti-immigrant sentiment as political instrument *****/
/* IV with exposure to anti-immigrant sentiment */
/* Raw data */
// Clear storage 
eststo clear
// Without control variables
tsset mx_id yr
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_anti_exp) active_exp anti_exp ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est1_)
// With control variables
eststo: xi: ivreg2 rem (dpt_tot_prop=sc_anti_exp) active_exp anti_exp pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est2_)
/* Winsorized data (0.5, 99.5) */
winsor2 anti_exp, cuts(0.5 99.5) suffix(_w1)
gen sc_anti_exp_w1 = active_exp_w1*anti_exp_w1
// Without control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_anti_exp_w1) active_exp_w1 anti_exp_w1 ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est3_)
// With control variables
eststo: xi: ivreg2 rem_w1 (dpt_tot_prop_w1=sc_anti_exp_w1) active_exp_w1 anti_exp_w1 pop ann_pr_mx avg_tmp_mx ib(first).yr ib(first).mx_id, robust first savefirst savefprefix(est4_)
/* Export table to LATEX using esttab. In LateX, set 'article' as document class, and install 'booktabs' and 'threeparttable' packages. Next, add \begin{document} and \end{document} appropriately, then add \begin{threeparttable} after \begin{table} as well as \end{threeparttable} before \end{table}. After, set table font size to \footnotesize. Next, move final eight lines of first table to end of second table. Delete \midrule between the the tables. Penultimately, consolidate notes by moving all of them from \multicolumn to middle of \begin{tablenotes} and \end{tablenotes}, which should sit between \end{tabular} and \end{threeparttable}. Set notes in \scriptsize. Last, put separate terms in Kleibergen-Paap F statistic.  */
esttab est1 est2 est3 est4 using "$data/iv_anti.tex", replace refcat(dpt_tot_prop "\emph{Second Stage}", nolabel) b(3) se(3) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) varlabels(dpt_tot_prop "\hspace{0.5cm} Deportations" active_exp "\hspace{0.5cm} Policy" anti_exp "\hspace{0.5cm} Anti-Immigrant Exposure" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber mtitle("\textit{1}" "\textit{2}" "\textit{3}" "\textit{4}") mgroups("\textit{Original}" "\textit{Winsorized (0.5, 99.5)}", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{)suffix(}) span erepeat(\cmidrule(lr){@span})) title(Effect of Deportations on Mexican States' Annual \newline Remittance Inflows (USD mil.)) rename(dpt_tot_prop_w1 dpt_tot_prop active_exp_w1 active_exp anti_exp_w1 anti_exp) stats(N F Fp widstat, fmt(0 3 3 3) label(Observations \(F\) Prob\(>\)F Kleibergen-Paap\(F\)statistic)) addnote("IV regression. Robust standard errors in parentheses. All models contain state and year fixed effects.") collabels(none) noobs booktabs
/* Append first stage results */ 
esttab est1_dpt_tot_prop est2_dpt_tot_prop est3_dpt_tot_prop_w1 est4_dpt_tot_prop_w1 using "$data/iv_anti.tex", append refcat(sc_anti_exp "\emph{First Stage}", nolabel) b(2) se(2) drop(*yr *mx_id) star(* 0.1 ** 0.05 *** 0.01) nomtitle varlabels(sc_anti_exp "\hspace{0.5cm} Policy $\times$ Anti-Immigrant Exposure" active_exp "\hspace{0.5cm} Policy" anti_exp "\hspace{0.5cm} Anti-Immigrant Exposure" pop "\hspace{0.5cm} Population (mil.)" ann_pr_mx "\hspace{0.5cm} Precipitation (mm)" avg_tmp_mx "\hspace{0.5cm} Temperature (ºC)" _cons "\hspace{0.5cm} Constant") nonumber rename(sc_anti_exp_w1 sc_anti_exp active_exp_w1 active_exp anti_exp_w1 anti_exp) collabels(none) noobs booktabs fragment
